package demo2;

class MyCircularQueue {
        public int[] elam;
        public int rear;
        public int front;
    public MyCircularQueue(int k) {
        elam = new int[k + 1];
    }
    
    public boolean enQueue(int value) {
        if(isFull()){
            return false;
        }
        elam[rear] = value;
        rear = (rear + 1) % elam.length;
        return true;
    }
    
    public boolean deQueue() {
        if(isEmpty()){
            return false;
        }
        front = (front + 1) % elam.length;
        return true;
    }
    
    public int Front() {
        if(isEmpty()){
            return -1;
        }
        return elam[front];
    }
    
    public int Rear() {
        if(isEmpty()){
            return -1;
        }
        int index = -1;
        if(rear == 0){
            index = elam.length - 1;
        }else{
            index = rear - 1;
        }
        return elam[index];
    }
    
    public boolean isEmpty() {
        return elam.length == rear;
    }
    
    public boolean isFull() {
        return (rear + 1) % elam.length == front;
    }
}